# -*- coding: utf-8 -*-
"""
@Time ： 2020-11-19 9:30
@Auth ： lixin
@Description：关联规则分析训练类

"""
from apyori import apriori
from sklearn import linear_model
from sklearn.cluster import KMeans

from algo.Algo_interface import Algo_interface
from sklearn import linear_model
from sklearn import metrics
from sklearn.ensemble import RandomForestClassifier
from sklearn import svm
# import api as runs
import numpy as np
import lightgbm as lgb
from sklearn import neural_network
from xgboost.sklearn import XGBClassifier
from sklearn.ensemble import GradientBoostingClassifier
import json

class AssociationRuleAnalysis(Algo_interface):
    def __init__(self, model_type, model_name, model_params):
        self.task_type = model_type
        self.model_name = model_name
        self.model_params = model_params
        self.model = None
        self.build_model()
        # return self.model

    def set_model(self, model):
        self.model = model
        return 1

    def get_model(self):
        return self.model

    def build_model(self):
        if self.model_name == 'apriori':
            self.model =  None

    def train(self,data):
        result = apriori(transactions=data, **self.model_params)
        out = []
        for i in result:
            out.append(i)
        return out
    def predict(self,data):
        pass


def loadDataSet():
    return [[1, 2, 3, 4, 6], [2, 3, 4, 5, 6], [1, 2, 3, 5, 6], [1, 2, 4, 5, 6]]
if __name__ == '__main__':
    data=loadDataSet()
    model=AssociationRuleAnalysis('1','apriori',{"min_support":0.5})
    print(model.train(data))